<?php
/**
 * Created by PhpStorm.
 * User: GadflyBSD
 * Date: 14-7-14
 * Time: 下午5:13
 */

namespace Good\Controller;
use Common\Controller\PublicController;

class CommonController extends PublicController {
	 /**
	 * 递归获得分类信息
	 * @param array $param
	 * @return array
	 */
	protected function getCategory($param = array()){
		$param['catid'] = (is_null($param['catid']))?0:$param['catid'];
		$param['item'] = (is_null($param['item']))?0:$param['item'];
		$flag = '&nbsp;';
		for($i=0; $i<$param['item']; $i++){
			$flag .= '&nbsp;&nbsp;&nbsp;&nbsp;';
		}
		$flag .= '+--';
		$data = M('PluginGoodCategory');
		$list = $data->where('upid = '.$param['catid'])->order('displayorder ASC')->select();
		foreach($list AS $v){
			$count = $data->where('upid='.$v['catid'])->count();
			$return['select'][] = array(
				'catid'     => $v['catid'],
				'catname'   => $flag.$v['catname'],
				'keyname'   => $v['keyname']
			);
			$return['nodes'][] = array_merge($v, array('open' => true));
			if($count>0){
				$new = array('catid' => $v['catid'], 'item' => ($param['item']+1));
				$return = array_merge_recursive($return, $this->getCategory($new));
			}
		}
		//$return['json'] = getJson($return['nodes']);
		return convert_encoding($return, 'GBK', 'UTF-8');
	}
} 